package com.supersit.GZFDA.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.supersit.GZFDA.R;
import com.supersit.GZFDA.entity.Business;

public class BusinessListAdapter extends BaseAdapter {
	private List<Business> businesss;
	private Context context;

	public BusinessListAdapter(List<Business> businesss, Context context) {
		super();
		this.businesss = businesss;
		this.context = context;
	}

	public List<Business> getBusinesss() {
		return businesss;
	}

	public void setBusinesss(List<Business> businesss) {
		this.businesss = businesss;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return businesss.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return businesss.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View conteneView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (conteneView == null) {
			holder = new ViewHolder();
			conteneView = LayoutInflater.from(context).inflate(
					R.layout.item_search_data_item, null);
			holder.businessName = (TextView) conteneView
					.findViewById(R.id.tv_search_item_business_name);
			holder.operateAddress = (TextView) conteneView
					.findViewById(R.id.tv_search_itm_address);
			holder.num = (TextView) conteneView
					.findViewById(R.id.tv_search_num);
			conteneView.setTag(holder);
		} else {
			holder = (ViewHolder) conteneView.getTag();
		}
		holder.businessName.setText(businesss.get(arg0).getBusiness_name());
		holder.operateAddress
				.setText(businesss.get(arg0).getOperate_addrress());
		holder.num.setText((arg0 + 1) + "");

		return conteneView;
	}

	class ViewHolder {
		TextView businessName;
		TextView operateAddress;
		TextView num;
	}

	public void clearList() {
		this.businesss.clear();
	}
}
